/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2024-03-05 09:18:53
 * @LastEditors: htang
 * @LastEditTime: 2024-03-05 10:43:36
 */
import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

const API = {
  // 站点列表分页
  page: '/equipment/zone/page',
  // 站点列表
  list: '/equipment/zone/list',
  // 增加equipment
  insert: '/equipment/zone/insert',
  // 编辑equipment
  modify: '/equipment/zone/modify',
  // 删除equipment
  delete: '/equipment/zone/delete',
  // equipment基础信息
  info: '/equipment/zone/info',
}

/**
 * 获取equipment列表
 * @returns
 */
export const equipmentZoneListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}

/**
 * 根据ID查询equipment
 * @param {int} id
 * @returns
 */
export const equipmentZoneInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 新增设备防区数据
 * @param {int} equipmentCode 设备编码
 * @param {int} stationCode 站点编码
 * @param {int} zoneCode 防区编号
 * @param {int} zoneName 防区名称
 * @returns
 */
export const equipmentZoneAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.insert, data }).then((res) => {
          resolve(true);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 新增设备防区数据
 * @param {int} equipmentCode 设备编码
 * @param {int} stationCode 站点编码
 * @param {int} zoneCode 防区编号
 * @param {int} zoneName 防区名称
 * @returns
 */
export const equipmentZoneModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(true);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除设备防区数据接口
 * @param {*} id
 * @returns
 */
export const equipmentZoneDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前防区设备数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}